package com.wanhe.mealbookmodule;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by chendeji on 25/6/15.
 */
public class SettingFactory {

    private SharedPreferences sharedPreferences;

    private static SettingFactory ourInstance;


    public static SettingFactory getInstance() {
        if (ourInstance == null) {
            ourInstance = new SettingFactory();
        }
        return ourInstance;
    }

    private SettingFactory() {
    }

    public void registSharePreferencesListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
        if (sharedPreferences != null) {
            sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
        }
    }

    public void unregistSharePreferencesListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
        if (sharedPreferences != null) {
            sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
        }
    }

    public void init(Context context, String name) {
        if (sharedPreferences == null) {
            sharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        }
    }

    public SharedPreferences getSharedPreferences(){
        return this.sharedPreferences;
    }

}
